package com.usc.blog.web.controller;

import java.util.Date;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.usc.blog.pojo.BlogData;
import com.usc.blog.pojo.BlogDataExample;
import com.usc.blog.pojo.User;
import com.usc.blog.service.BlogDataService;

/**
 *
 * @版权: Copyright (c) 2016-2017 *********公司技术开发部
 * @author : huangjiapeng
 * @E-mail:1625545295@qq.com
 * @版本: 1.0
 * @创建日期: 2019年5月14日 下午4:51:21
 * @ClassName AddBlog
 * @类描述-Description: TODO
 * @修改记录:
 * @版本: 1.0
 */
@Controller
@RequestMapping("addData")
public class AddDataController {
	@Autowired
	public BlogDataService blogDataService;

	@RequestMapping("/toAddBolgUI")
	public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
		return "user/addblog";
	}

	@RequestMapping("/toAddBolg")
	public String addBolg(HttpServletRequest request, HttpServletResponse response, Model model, BlogData blogdata,
			HttpSession session) {
		// 将资料信息保存到数据库和磁盘
		System.out.println("blogdata=" + blogdata);
		String dataurl = (String) session.getAttribute("dataurl");
		System.out.println("dataurl=" + dataurl);
		User u = (User) session.getAttribute("currentUser");
		blogdata.setUsername(u.getUsername());
		blogdata.setStatus(1);
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		blogdata.setBlogdataid(uuid);
		// 将blogdata保存到数据库
		blogdata.setDataurl(dataurl);
		// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd
		// HH:mm:ss");
		Date date = new Date();
		blogdata.setUpdatetime(date);
		blogdata.setCreatedate(date);
		BlogDataExample example = new BlogDataExample();
		// Criteria createCriteria = example.createCriteria();
		int insert = blogDataService.insert(blogdata);
		System.out.println("输入" + insert);
		return "user/addblog";
	}
}
